# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1.获取中移动项目数据库的信息生成相应的对账文件
2.获取数据库信息并对信息进行组合
3.更新数据库字段信息
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import pymysql
from deal_excel import get_info


db = pymysql.connect(
        host="rm-wz905n9ed226krle9.mysql.rds.aliyuncs.com",    # 生产环境
        user="rds2zenglingwei",             # 测试：dev   开发：root
        password="oKa#sPoj",       # 测试：dev   开发：123456
        port=3306,
        use_unicode=True,
        charset="utf8",
        database="msydloandb")           # qdzjmsloandb  ， bxloandb  msydloandb, msreport
cursor = db.cursor()


def msydloan(id_card):
    sql = 'select act_brw_id_no, brw_ord_no,mbl_no,brw_ord_dt,dep_prov_no from pro_hb_loan where act_brw_id_no="%s";' %(id_card)
    cursor.execute(sql)
    results = cursor.fetchall()
    row = []
    for result in results:
        for data in result:
            try:
                data = data.strftime('%Y%-m%-d%')[0:8]
            except:
                data = str(data)
            row.append(data)
    print(row)


def main():
    id_cards = get_info('E:\zenglingwei\\test\sample.xlsx')
    for idCard in id_cards:
        msydloan(idCard[0])


if __name__ == '__main__':
    main()